package com.apes.fico.finance.model.costcollect;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.masterdata.frame.model.Dept;
import com.apes.scm.masterdata.product.model.ServeType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = ProportionServeType.CONST_TABLE_NAME)
public class ProportionServeType extends Model {
    public final static String CONST_TABLE_NAME = "gl_proportion_serve_type";

    @Id
    @Column(name = "id", nullable = false, length = 32)
    @ApesGenerator(code = CONST_TABLE_NAME, name = "服务类型占比", padding = 8)
    @Comment("编号")
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id", nullable = false)
    @Comment("部门")
    private Dept dept;

    @NotNull
    @Column(name = "year_month")
    @Comment("年月")
    private Date yearMonth;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "serve_type_id", referencedColumnName = "id",nullable = false)
    @Comment("服务类型")
    private ServeType serveType;

    @Column(name = "amt", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("金额")
    private double amt = 0;

    @Column(name = "proportion", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("占比")
    private double proportion = 0;
}
